﻿using System;
using System.Net.Sockets;

namespace Bouyei.NetFactory
{
    internal class Utils
    {
        internal static void SafeCloseSocket(Socket socket)
        {
            if (socket == null) return;

            try
            {
                socket.Shutdown(SocketShutdown.Both);
            }
            catch (ObjectDisposedException)
            {
                return;
            }
            catch
            { }
            try
            {
                socket.Disconnect(false);
            }
            catch (Exception) { }
            try
            {
                socket.Dispose();
            }
            catch
            { }
        }
    }
}
